package com.tekj.cxqcb.view.Module.fragment;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.tekj.cxqcb.MainBActivity;
import com.tekj.cxqcb.R;
import com.tekj.cxqcb.operation.BusinessDao;
import com.tekj.cxqcb.operation.resultBean.SelectExpandListBean;
import com.tekj.cxqcb.view.Module.adapter.DevelopmentRecordAdapter;
import com.tekj.cxqcb.view.Module.decoration.SpacesItemDecoration;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import common.base.fragment.BaseFragment;
import common.base.operationHelper.Bean.BindingViewBean;

/**
 * 渠道拓展记录
 */
public class DevelopmentRecordFragment extends BaseFragment {
    @BindView(R.id.rv_main)
    RecyclerView rvMain;
    @BindView(R.id.srl_main)
    SwipeRefreshLayout srlMain;
    DevelopmentRecordAdapter mAdapter;

    BusinessDao businessDao;
    int page = 1;
    int type;

    @Override
    public void init() {
        businessDao = new BusinessDao(activity, this);
        type = getArguments().getInt("type");
        mAdapter = new DevelopmentRecordAdapter(null);
        rvMain.setLayoutManager(new LinearLayoutManager(activity));
        rvMain.setAdapter(mAdapter);
        rvMain.addItemDecoration(new SpacesItemDecoration(2));

        mAdapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
            @Override
            public void onLoadMoreRequested() {

            }
        }, rvMain);

        srlMain.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {

            }
        });

        businessDao.SelectExpandList(MainBActivity.User.getUserId(), type, page);
    }

    @Override
    public int setLayout() {
        return R.layout.fragment_development_record;
    }

    @Override
    public void initLoadStart() {

    }

    @Override
    public void initLoadEnd() {

    }

    @Override
    public void initBindingView(Object mBean) {
        BindingViewBean bindingViewBean = (BindingViewBean) mBean;
        switch (bindingViewBean.getmEnumStatus()) {
            case 拓展记录列表:
                SelectExpandListBean listBean = (SelectExpandListBean) bindingViewBean.getBean();
                if (listBean.getCode().equals("0000000")) {
                    if (page == 1) {
                        mAdapter.setNewData(listBean.getData().getList());
                    } else {
                        mAdapter.addData(listBean.getData().getList());
                    }
                    mAdapter.loadMoreComplete();
                    if (listBean.getData().getList().size() < 10) {
                        mAdapter.loadMoreEnd();
                    }
                }

                break;
        }

    }

}
